#include<bits/stdc++.h>

using namespace std;
using oi = ostream_iterator<int>;
int main() {
	int a[] = {1, 2, 3};
	int n = sizeof(a) / sizeof(a[0]);
	copy(a, a + n, oi(cout, " "));
	cout << endl;
	next_permutation(a, a + n);
	copy(a, a + n, oi(cout, " "));
	cout << endl;
	prev_permutation(a, a + n);
	copy(a, a + n, oi(cout, " "));
	cout << endl;

	return 0;
}
